﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class clsTaiSanCoDinh
    {
        private double mDaKhauHao = 0.0;
        private double mDaKhauHaoBanDau = 0.0;
        private string mDienGiai = "";
        private string mDuLieu = "";
        private int mDuyet = 0;
        private double mGiaTriConLai = 0.0;
        private double mGiaTriConLaiBanDau = 0.0;
        private byte[] mImg;
        private string mKhoa = "";
        private string mKhoaBoPhan = "";
        private string mKhoaBoPhanSuDung = "";
        private string mKhoaDiemDat = "";
        private string mKhoaDonVi = "";
        private string mKhoaDonViTinh = "";
        private string mKhoaHangSanXuat = "";
        private string mKhoaLoaiTaiSan = "";
        private string mKhoaNhaCungCap = "";
        private string mKhoaNhanVienSuDung = "";
        private string mKhoaNuocSanXuat = "";
        private string mKhoaSanPham = "";
        private string mKhoaTKChiPhi = "";
        private string mKhoaTKKhauHao = "";
        private string mKhoaTKNguyenGia = "";
        private string mLoaiTien = "";
        private string mLyDoTang = "";
        private string mMa = "";
        private double mNamSanXuat = 0.0;
        private string mNamThangTinhKhauHao = "";
        private string mNgayMua = "";
        private string mNgayThanhLy = "";
        private double mNguyenGia = 0.0;
        private double mNguyenGiaNT = 0.0;
        private string mSoHieuTaiSan = "";
        private string mTenAnh = "";
        private string mTenViet = "";
        private int mThoiGianBaoHanh = 0;
        private int mThoiGianSuDung = 0;
        private string mTinhTrang = "";
        private double mTriGiaKhauHao = 0.0;
        private double mTyGia = 0.0;

        public bool CheckGhiSoGiam(string pKhoa)
        {
            bool flag=false;
            string commandText = "";
            try
            {
                commandText = "SELECT KhoaTaiSanCoDinh FROM FA_ChungTuTangGiamTaiSan WHERE RTRIM(KhoaTaiSanCoDinh) = '" + pKhoa + "' and Loai = 0 ";
                if (LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(DBHelper.ExecuteScalar(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0])), "", modGeneral.TypeOfValue.Nothing).ToString().Trim().Trim() != "")
                {
                    return true;
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag = true;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool CheckGhiSoTang(string pKhoa)
        {
            bool flag=false;
            string commandText = "";
            try
            {
                commandText = "SELECT KhoaTaiSanCoDinh FROM FA_ChungTuTangGiamTaiSan WHERE RTRIM(KhoaTaiSanCoDinh) = '" + pKhoa + "' and Loai = 1 ";
                if (LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(DBHelper.ExecuteScalar(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0])), "", modGeneral.TypeOfValue.Nothing).ToString().Trim().Trim() != "")
                {
                    return true;
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag = true;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool DaSuDung(string strKhoaTaiSan)
        {
            bool flag=false;
            string commandText = "";
            try
            {
                commandText = "SELECT Top 1 KhoaTaiSan FROM FA_QuaTrinhKhauHao WHERE RTRIM(KhoaTaiSan) = '" + strKhoaTaiSan.Trim() + "'";
                flag = LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(DBHelper.ExecuteScalar(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0])), "", modGeneral.TypeOfValue.Nothing).ToString().Trim().Trim() != "";
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag = true;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool DaTinhKhauHao(string strNamThang)
        {
            bool flag=false;
            string commandText = "";
            try
            {
                commandText = "SELECT Top 1 KhoaTaiSan FROM FA_QuaTrinhKhauHao WHERE RTRIM(NamThang) = '" + strNamThang.Trim() + "'";
                flag = LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(DBHelper.ExecuteScalar(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0])), "", modGeneral.TypeOfValue.Nothing).ToString().Trim().Trim() != "";
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag = true;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool DelData(string pKhoa)
        {
            bool flag=false;
            string commandText = "";
            try
            {
                commandText = "DELETE FROM FA_ChiTietPhuTungTaiSan WHERE KhoaTaiSan = '" + pKhoa.Trim() + "'";
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                commandText = "DELETE FROM FA_TaiSanCoDinh WHERE Khoa = '" + pKhoa.Trim() + "'";
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable GetDataBangTinhKhauHao(string strNamThang, string strKhoaDonVi, int IntIn)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[4];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, strNamThang);
                commandParameters[2] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[3] = DBHelper.createParameter("@CachIn", DbType.Double, ParameterDirection.Input, IntIn);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "FA_BC_BangTinhKhauHao", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public byte[] GetImage(string pKhoa)
        {
            byte[] buffer;
            try
            {
                object obj2 = " SELECT Img FROM FA_TaisanCoDinh WHERE Khoa = '" + pKhoa + "'";
                buffer = (byte[]) LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(DBHelper.ExecuteScalar(modGeneral.ConnectionString, CommandType.Text, Conversions.ToString(obj2), new IDataParameter[0])), null, modGeneral.TypeOfValue.Nothing);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                buffer = null;
                ProjectData.ClearProjectError();
                return buffer;
                ProjectData.ClearProjectError();
            }
            return buffer;
        }

        public DataTable GetList(string strCondition = "")
        {
            DataTable table;
            string str2 = "";
            try
            {
                if (strCondition.Trim() != "")
                {
                    str2 = " WHERE " + strCondition;
                }
                string commandText = "SELECT Khoa, Ma, Ten" + modGeneral.H_LANGUAGE + " as TenTaiSan, NamSanXuat, dbo.Char2Date(NgayMua) as NgayMua,  NguyenGia, DaKhauHao, GiaTriConLai, DienGiai FROM FA_TaiSanCoDinh " + str2 + " ORDER BY 2, 5, 4";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetListDetails(string strKhoa)
        {
            DataTable table;
            string str2 = "";
            try
            {
                string commandText = "SELECT Khoa, Ma, Ten" + modGeneral.H_LANGUAGE + " as TenTaiSan, NamSanXuat, dbo.Char2Date(NgayMua) as NgayMua,  NguyenGia, DaKhauHao, GiaTriConLai, DienGiai FROM FA_TaiSanCoDinh " + str2 + " ORDER BY 2, 5, 4";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetListKhauHaoThang(string strNamThang, string strKhoaDonVi)
        {
            DataTable table;
            try
            {
                string commandText = "SELECT TS.Khoa, TS.Ma, TS.Ten" + modGeneral.H_LANGUAGE + " as TenTaiSan, KH.NguyenGia, KH.KhauHaoLuyKe,  KH.TriGiaKhauHao, KH.GiaTriConLai, TKN.SoTaiKhoan as TaiKhoanNo, TKC.SoTaiKhoan as TaiKhoanCo,  BP.Ma as BoPhan, SP.Ma As SanPham, HD.SoHopDong as HopDong  FROM FA_QuaTrinhKhauHao KH LEFT JOIN FA_TaiSanCoDinh TS on KH.KhoaTaiSan = TS.Khoa  LEFT JOIN DM_TaiKhoan TKN on KH.KhoaTaiKhoanNo = TKN.Khoa  LEFT JOIN DM_TaiKhoan TKC on KH.KhoaTaiKhoanCo = TKC.Khoa  LEFT JOIN DM_DonViBoPhan BP on KH.KhoaBoPhan = BP.Khoa  LEFT JOIN DM_SanPhamCongViec SP on KH.KhoaSanPham = SP.Khoa  LEFT JOIN DM_HopDong HD on KH.KhoaHopDong = HD.Khoa  WHERE KH.NamThang = '" + strNamThang.Trim() + "' and KH.KhoaDonVi = '" + strKhoaDonVi.Trim() + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetListMain(string strCondition = "")
        {
            DataTable table;
            string str2 = "";
            try
            {
                if (strCondition.Trim() != "")
                {
                    str2 = " WHERE " + strCondition;
                }
                string commandText = "SELECT TS.Khoa, TS.Ma, TS.SoHieuTaiSan, TS.Ten" + modGeneral.H_LANGUAGE + " as TenTaiSan, dbo.Char2Date(TS.NgayMua) as NgayMua,  DC.Ten" + modGeneral.H_LANGUAGE + " as TinhTrang, TS.NguyenGia, TS.DaKhauHao, TS.GiaTriConLai, TS.ThoiGianSuDung,  TS.TriGiaKhauHao  FROM FA_TaiSanCoDinh TS LEFT JOIN HT_DungChung DC ON TS.TinhTrang = DC.Ma and DC.Loai = '0000000006' " + str2 + " ORDER BY TS.Ma, TS.SoHieuTaiSan";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool HuyKhauHao(string strNamThang, string strKhoaChungTu, string strKhoaDonVi)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[4];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, strNamThang);
                commandParameters[1] = DBHelper.createParameter("@KhoaChungTu", DbType.Int64, ParameterDirection.Input, strKhoaChungTu);
                commandParameters[2] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[3] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "FA_sp_TinhKhauHaoDel", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[3].Value, 0, false))
                {
                    return true;
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool InsertImage()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x20];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@Img", DbType.Decimal, ParameterDirection.Input, this.mImg);
                bool flag2 = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "DM_TaiSanImg", commandParameters) > 0;
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Load(string pKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                string commandText = "SELECT * FROM FA_TaisanCoDinh WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, commandParameters);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mMa = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mTenViet = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mTenAnh = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNuocSanXuat = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mKhoaHangSanXuat = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mNamSanXuat = Conversions.ToDouble(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetDecimal));
                    this.mThoiGianBaoHanh = Conversions.ToInteger(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetInt32));
                    this.mNgayMua = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhaCungCap = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDiemDat = Conversions.ToString(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetString));
                    this.mKhoaBoPhanSuDung = Conversions.ToString(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhanVienSuDung = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mTinhTrang = Conversions.ToString(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDonViTinh = Conversions.ToString(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetDecimal));
                    this.mNguyenGiaNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetDecimal));
                    this.mNguyenGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetDecimal));
                    this.mDaKhauHaoBanDau = Conversions.ToDouble(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetDecimal));
                    this.mDaKhauHao = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x15, modGeneral.typeOfColumn.GetDecimal));
                    this.mGiaTriConLaiBanDau = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x16, modGeneral.typeOfColumn.GetDecimal));
                    this.mGiaTriConLai = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x17, modGeneral.typeOfColumn.GetDecimal));
                    this.mThoiGianSuDung = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x18, modGeneral.typeOfColumn.GetInt32));
                    this.mTriGiaKhauHao = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x19, modGeneral.typeOfColumn.GetDecimal));
                    this.mNamThangTinhKhauHao = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1a, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTKNguyenGia = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1b, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTKKhauHao = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1c, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTKChiPhi = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1d, modGeneral.typeOfColumn.GetString));
                    this.mKhoaBoPhan = Conversions.ToString(modGeneral.GetValue(dataReader, 30, modGeneral.typeOfColumn.GetString));
                    this.mKhoaSanPham = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1f, modGeneral.typeOfColumn.GetString));
                    this.mKhoaLoaiTaiSan = Conversions.ToString(modGeneral.GetValue(dataReader, 0x20, modGeneral.typeOfColumn.GetString));
                    this.mLyDoTang = Conversions.ToString(modGeneral.GetValue(dataReader, 0x21, modGeneral.typeOfColumn.GetString));
                    this.mSoHieuTaiSan = Conversions.ToString(modGeneral.GetValue(dataReader, 0x22, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDonVi = Conversions.ToString(modGeneral.GetValue(dataReader, 0x23, modGeneral.typeOfColumn.GetString));
                    this.mNgayThanhLy = Conversions.ToString(modGeneral.GetValue(dataReader, 0x24, modGeneral.typeOfColumn.GetString));
                    this.mDuLieu = Conversions.ToString(modGeneral.GetValue(dataReader, 0x25, modGeneral.typeOfColumn.GetString));
                    this.mDuyet = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x26, modGeneral.typeOfColumn.GetInt32));
                    commandText = " SELECT Img FROM FA_TaisanCoDinh WHERE Khoa = '" + pKhoa + "'";
                    this.mImg = (byte[]) LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(DBHelper.ExecuteScalar(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0])), null, modGeneral.TypeOfValue.Nothing);
                    dataReader.Close();
                    return true;
                }
                dataReader.Close();
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save(string pTask)
        {
            bool flag2;
            IDataParameter[] commandParameters = new IDataParameter[0x27];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@Ma", DbType.Int64, ParameterDirection.Input, this.mMa);
                commandParameters[2] = DBHelper.createParameter("@TenViet", DbType.Int64, ParameterDirection.Input, this.mTenViet);
                commandParameters[3] = DBHelper.createParameter("@TenAnh", DbType.Int64, ParameterDirection.Input, this.mTenAnh);
                commandParameters[4] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[5] = DBHelper.createParameter("@KhoaNuocSanXuat", DbType.Int64, ParameterDirection.Input, this.mKhoaNuocSanXuat);
                commandParameters[6] = DBHelper.createParameter("@KhoaHangSanXuat", DbType.Int64, ParameterDirection.Input, this.mKhoaHangSanXuat);
                commandParameters[7] = DBHelper.createParameter("@NamSanXuat", DbType.Date, ParameterDirection.Input, this.mNamSanXuat);
                commandParameters[8] = DBHelper.createParameter("@ThoiGianBaoHanh", DbType.Double, ParameterDirection.Input, this.mThoiGianBaoHanh);
                commandParameters[9] = DBHelper.createParameter("@NgayMua", DbType.Int64, ParameterDirection.Input, this.mNgayMua);
                commandParameters[10] = DBHelper.createParameter("@KhoaNhaCungCap", DbType.Int64, ParameterDirection.Input, this.mKhoaNhaCungCap);
                commandParameters[11] = DBHelper.createParameter("@KhoaDiemDat", DbType.Int64, ParameterDirection.Input, this.mKhoaDiemDat);
                commandParameters[12] = DBHelper.createParameter("@KhoaBoPhanSuDung", DbType.Int64, ParameterDirection.Input, this.mKhoaBoPhanSuDung);
                commandParameters[13] = DBHelper.createParameter("@KhoaNhanVienSuDung", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVienSuDung);
                commandParameters[14] = DBHelper.createParameter("@TinhTrang", DbType.Int64, ParameterDirection.Input, this.mTinhTrang);
                commandParameters[15] = DBHelper.createParameter("@KhoaDonViTinh", DbType.Int64, ParameterDirection.Input, this.mKhoaDonViTinh);
                commandParameters[0x10] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, this.mLoaiTien);
                commandParameters[0x11] = DBHelper.createParameter("@TyGia", DbType.Date, ParameterDirection.Input, this.mTyGia);
                commandParameters[0x12] = DBHelper.createParameter("@NguyenGiaNT", DbType.Date, ParameterDirection.Input, this.mNguyenGiaNT);
                commandParameters[0x13] = DBHelper.createParameter("@NguyenGia", DbType.Date, ParameterDirection.Input, this.mNguyenGia);
                commandParameters[20] = DBHelper.createParameter("@DaKhauHaoBanDau", DbType.Date, ParameterDirection.Input, this.mDaKhauHaoBanDau);
                commandParameters[0x15] = DBHelper.createParameter("@DaKhauHao", DbType.Date, ParameterDirection.Input, this.mDaKhauHao);
                commandParameters[0x16] = DBHelper.createParameter("@GiaTriConLaiBanDau", DbType.Date, ParameterDirection.Input, this.mGiaTriConLaiBanDau);
                commandParameters[0x17] = DBHelper.createParameter("@GiaTriConLai", DbType.Date, ParameterDirection.Input, this.mGiaTriConLai);
                commandParameters[0x18] = DBHelper.createParameter("@ThoiGianSuDung", DbType.Double, ParameterDirection.Input, this.mThoiGianSuDung);
                commandParameters[0x19] = DBHelper.createParameter("@TriGiaKhauHao", DbType.Date, ParameterDirection.Input, this.mTriGiaKhauHao);
                commandParameters[0x1a] = DBHelper.createParameter("@NamThangTinhKhauHao", DbType.Int64, ParameterDirection.Input, this.mNamThangTinhKhauHao);
                commandParameters[0x1b] = DBHelper.createParameter("@KhoaTKNguyenGia", DbType.Int64, ParameterDirection.Input, this.mKhoaTKNguyenGia);
                commandParameters[0x1c] = DBHelper.createParameter("@KhoaTKKhauHao", DbType.Int64, ParameterDirection.Input, this.mKhoaTKKhauHao);
                commandParameters[0x1d] = DBHelper.createParameter("@KhoaTKChiPhi", DbType.Int64, ParameterDirection.Input, this.mKhoaTKChiPhi);
                commandParameters[30] = DBHelper.createParameter("@KhoaBoPhan", DbType.Int64, ParameterDirection.Input, this.mKhoaBoPhan);
                commandParameters[0x1f] = DBHelper.createParameter("@KhoaSanPham", DbType.Int64, ParameterDirection.Input, this.mKhoaSanPham);
                commandParameters[0x20] = DBHelper.createParameter("@KhoaLoaiTaiSan", DbType.Int64, ParameterDirection.Input, this.mKhoaLoaiTaiSan);
                commandParameters[0x21] = DBHelper.createParameter("@LyDoTang", DbType.Int64, ParameterDirection.Input, this.mLyDoTang);
                commandParameters[0x22] = DBHelper.createParameter("@SoHieuTaiSan", DbType.Int64, ParameterDirection.Input, this.mSoHieuTaiSan);
                commandParameters[0x23] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[0x24] = DBHelper.createParameter("@NgayThanhLy", DbType.Int64, ParameterDirection.Input, this.mNgayThanhLy);
                commandParameters[0x25] = DBHelper.createParameter("@DuLieu", DbType.Int64, ParameterDirection.Input, this.mDuLieu);
                commandParameters[0x26] = DBHelper.createParameter("@Duyet", DbType.Double, ParameterDirection.Input, this.mDuyet);
                bool flag = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "FA_sp_TaiSanCoDinh", commandParameters) > 0;
                if (this.mImg != null)
                {
                    this.InsertImage();
                }
                flag2 = flag;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag2 = false;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public string SearchByCode(string strCode, string strConditions = "")
        {
            string str4;
            string commandText = "";
            string str3 = "";
            string str = "";
            try
            {
                if (strCode.Trim() != "")
                {
                    str3 = " AND RTRIM(Ma) = '" + strCode.Trim() + "'";
                }
                if (strConditions.Trim() != "")
                {
                    str3 = str3 + " AND " + strConditions;
                }
                commandText = "SELECT Khoa, Ma, Ten" + modGeneral.H_LANGUAGE + " as Ten  FROM FA_TaiSanCoDinh WHERE Active = 1 " + str3;
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    str = modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString).ToString() + "|" + modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString).ToString() + "|" + modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString).ToString();
                }
                dataReader.Close();
                str4 = str;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                str4 = "";
                ProjectData.ClearProjectError();
                return str4;
                ProjectData.ClearProjectError();
            }
            return str4;
        }

        public void SetBlank()
        {
            this.mKhoa = "";
            this.mMa = "";
            this.mTenViet = "";
            this.mTenAnh = "";
            this.mDienGiai = "";
            this.mKhoaNuocSanXuat = "";
            this.mKhoaHangSanXuat = "";
            this.mNamSanXuat = 0.0;
            this.mThoiGianBaoHanh = 0;
            this.mNgayMua = "";
            this.mKhoaNhaCungCap = "";
            this.mKhoaDiemDat = "";
            this.mKhoaBoPhanSuDung = "";
            this.mKhoaNhanVienSuDung = "";
            this.mTinhTrang = "";
            this.mKhoaDonViTinh = "";
            this.mLoaiTien = "";
            this.mTyGia = 0.0;
            this.mNguyenGiaNT = 0.0;
            this.mNguyenGia = 0.0;
            this.mDaKhauHaoBanDau = 0.0;
            this.mDaKhauHao = 0.0;
            this.mGiaTriConLaiBanDau = 0.0;
            this.mGiaTriConLai = 0.0;
            this.mThoiGianSuDung = 0;
            this.mTriGiaKhauHao = 0.0;
            this.mNamThangTinhKhauHao = "";
            this.mKhoaTKNguyenGia = "";
            this.mKhoaTKKhauHao = "";
            this.mKhoaTKChiPhi = "";
            this.mKhoaBoPhan = "";
            this.mKhoaSanPham = "";
            this.mKhoaLoaiTaiSan = "";
            this.mLyDoTang = "";
            this.mSoHieuTaiSan = "";
            this.mKhoaDonVi = "";
            this.mNgayThanhLy = "";
        }

        public DataTable ShowAllList()
        {
            DataTable table;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = " SELECT Khoa, Rtrim(Ma) as Ma, Rtrim(Ten" + modGeneral.H_LANGUAGE + ") as Ten  FROM FA_TaiSanCoDinh ORDER BY Ma ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable ShowList()
        {
            DataTable table;
            string commandText = "";
            try
            {
                commandText = " SELECT Khoa, Rtrim(Ma) as Ma, Rtrim(Ten" + modGeneral.H_LANGUAGE + ") as Ten  FROM FA_TaiSanCoDinh WHERE Active = 1 ORDER BY Ma ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable ShowListByField(string strFieldList, string strConditions = "", string strOrder = "")
        {
            DataTable table;
            string commandText = "";
            IDataParameter parameter = null;
            string str3 = "";
            string str = "";
            strFieldList = Strings.Replace(strFieldList, "|", ",", 1, -1, CompareMethod.Binary);
            try
            {
                if (strConditions.Trim() != "")
                {
                    str3 = " WHERE " + strConditions;
                }
                if (strOrder.Trim() != "")
                {
                    str = " ORDER BY " + strOrder;
                }
                commandText = "Select Khoa, Ma, TenVIET, NamSanXuat, dbo.Char2Date(NgayMua) as NgayMua, NguyenGia, DaKhauHao, GiaTriConLai, DienGiai, ThoiGianBaoHanh, NamThangTinhKhauHao as NamThangTinhKauHao ,LoaiTien, TyGia, NguyenGiaNT FROM FA_TaiSanCoDinh " + str3 + " ORDER BY 2, 5, 4";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable ShowListReport()
        {
            DataTable table;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = "select TSCD.Khoa, TSCD.Ma, TSCD.TenViet, TSCD.TenAnh, TSCD.DienGiai, TSCD.NamSanXuat, TSCD.ThoiGianBaoHanh, TSCD.NgayMua, TSCD.LoaiTien, TSCD.TyGia, TSCD.NguyenGiaNT, TSCD.NguyenGia, TSCD.DaKhauHao, TSCD.GiaTriConLai, TSCD.ThoiGianSuDung, TSCD.TriGiaKhauHao, TSCD.NamThangTinhKhauHao, TSCD.KhoaTKNguyenGia as KhoaTKNguyenGia, TSCD.KhoaTKKhauHao as KhoaTKKhauHao, TSCD.KhoaTKChiPhi as KhoaTKChiPhi From FA_TaiSanCoDinh as TSCD LEFT JOIN DM_QuocGia QG ON QG.Khoa = TSCD.KhoaNuocSanXuat";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool TinhKhauHao(string strNamThang, string strKhoaChungTu, string strSoChungTu, string strNgayChungTu, string strDienGiai, string strLoaiTien, string strKhoaDonVi)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[8];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, strNamThang);
                commandParameters[1] = DBHelper.createParameter("@KhoaChungTu", DbType.Int64, ParameterDirection.Input, strKhoaChungTu);
                commandParameters[2] = DBHelper.createParameter("@SoChungTu", DbType.Int64, ParameterDirection.Input, strSoChungTu);
                commandParameters[3] = DBHelper.createParameter("@NgayChungTu", DbType.Int64, ParameterDirection.Input, strNgayChungTu);
                commandParameters[4] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, strDienGiai);
                commandParameters[5] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, strLoaiTien);
                commandParameters[6] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[7] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "FA_sp_TinhKhauHao", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[7].Value, 0, false))
                {
                    return true;
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool TrungMa(string pMa, string pKhoa)
        {
            bool flag2;
            string commandText = "";
            IDataParameter parameter = null;
            try
            {
                commandText = "SELECT * FROM FA_TaiSanCoDinh WHERE RTRIM(Ma) = '" + pMa.Trim() + "' AND RTRIM(Khoa) <> '" + pKhoa.Trim() + "'";
                bool flag = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0].Rows.Count > 0;
                flag2 = flag;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag2 = true;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public double DaKhauHao
        {
            get
            {
                return this.mDaKhauHao;
            }
            set
            {
                this.mDaKhauHao = value;
            }
        }

        public double DaKhauHaoBanDau
        {
            get
            {
                return this.mDaKhauHaoBanDau;
            }
            set
            {
                this.mDaKhauHaoBanDau = value;
            }
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string DuLieu
        {
            get
            {
                return this.mDuLieu;
            }
            set
            {
                this.mDuLieu = value;
            }
        }

        public int Duyet
        {
            get
            {
                return this.mDuyet;
            }
            set
            {
                this.mDuyet = value;
            }
        }

        public double GiaTriConLai
        {
            get
            {
                return this.mGiaTriConLai;
            }
            set
            {
                this.mGiaTriConLai = value;
            }
        }

        public double GiaTriConLaiBanDau
        {
            get
            {
                return this.mGiaTriConLaiBanDau;
            }
            set
            {
                this.mGiaTriConLaiBanDau = value;
            }
        }

        public byte[] Img
        {
            get
            {
                return this.mImg;
            }
            set
            {
                this.mImg = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string KhoaBoPhan
        {
            get
            {
                return this.mKhoaBoPhan;
            }
            set
            {
                this.mKhoaBoPhan = value;
            }
        }

        public string KhoaBoPhanSuDung
        {
            get
            {
                return this.mKhoaBoPhanSuDung;
            }
            set
            {
                this.mKhoaBoPhanSuDung = value;
            }
        }

        public string KhoaDiemDat
        {
            get
            {
                return this.mKhoaDiemDat;
            }
            set
            {
                this.mKhoaDiemDat = value;
            }
        }

        public string KhoaDonVi
        {
            get
            {
                return this.mKhoaDonVi;
            }
            set
            {
                this.mKhoaDonVi = value;
            }
        }

        public string KhoaDonViTinh
        {
            get
            {
                return this.mKhoaDonViTinh;
            }
            set
            {
                this.mKhoaDonViTinh = value;
            }
        }

        public string KhoaHangSanXuat
        {
            get
            {
                return this.mKhoaHangSanXuat;
            }
            set
            {
                this.mKhoaHangSanXuat = value;
            }
        }

        public string KhoaLoaiTaiSan
        {
            get
            {
                return this.mKhoaLoaiTaiSan;
            }
            set
            {
                this.mKhoaLoaiTaiSan = value;
            }
        }

        public string KhoaNhaCungCap
        {
            get
            {
                return this.mKhoaNhaCungCap;
            }
            set
            {
                this.mKhoaNhaCungCap = value;
            }
        }

        public string KhoaNhanVienSuDung
        {
            get
            {
                return this.mKhoaNhanVienSuDung;
            }
            set
            {
                this.mKhoaNhanVienSuDung = value;
            }
        }

        public string KhoaNuocSanXuat
        {
            get
            {
                return this.mKhoaNuocSanXuat;
            }
            set
            {
                this.mKhoaNuocSanXuat = value;
            }
        }

        public string KhoaSanPham
        {
            get
            {
                return this.mKhoaSanPham;
            }
            set
            {
                this.mKhoaSanPham = value;
            }
        }

        public string KhoaTKChiPhi
        {
            get
            {
                return this.mKhoaTKChiPhi;
            }
            set
            {
                this.mKhoaTKChiPhi = value;
            }
        }

        public string KhoaTKKhauHao
        {
            get
            {
                return this.mKhoaTKKhauHao;
            }
            set
            {
                this.mKhoaTKKhauHao = value;
            }
        }

        public string KhoaTKNguyenGia
        {
            get
            {
                return this.mKhoaTKNguyenGia;
            }
            set
            {
                this.mKhoaTKNguyenGia = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string LyDoTang
        {
            get
            {
                return this.mLyDoTang;
            }
            set
            {
                this.mLyDoTang = value;
            }
        }

        public string Ma
        {
            get
            {
                return this.mMa;
            }
            set
            {
                this.mMa = value;
            }
        }

        public double NamSanXuat
        {
            get
            {
                return this.mNamSanXuat;
            }
            set
            {
                this.mNamSanXuat = value;
            }
        }

        public string NamThangTinhKhauHao
        {
            get
            {
                return this.mNamThangTinhKhauHao;
            }
            set
            {
                this.mNamThangTinhKhauHao = value;
            }
        }

        public string NgayMua
        {
            get
            {
                return this.mNgayMua;
            }
            set
            {
                this.mNgayMua = value;
            }
        }

        public string NgayThanhLy
        {
            get
            {
                return this.mNgayThanhLy;
            }
            set
            {
                this.mNgayThanhLy = value;
            }
        }

        public double NguyenGia
        {
            get
            {
                return this.mNguyenGia;
            }
            set
            {
                this.mNguyenGia = value;
            }
        }

        public double NguyenGiaNT
        {
            get
            {
                return this.mNguyenGiaNT;
            }
            set
            {
                this.mNguyenGiaNT = value;
            }
        }

        public string SoHieuTaiSan
        {
            get
            {
                return this.mSoHieuTaiSan;
            }
            set
            {
                this.mSoHieuTaiSan = value;
            }
        }

        public string TenAnh
        {
            get
            {
                return this.mTenAnh;
            }
            set
            {
                this.mTenAnh = value;
            }
        }

        public string TenViet
        {
            get
            {
                return this.mTenViet;
            }
            set
            {
                this.mTenViet = value;
            }
        }

        public int ThoiGianBaoHanh
        {
            get
            {
                return this.mThoiGianBaoHanh;
            }
            set
            {
                this.mThoiGianBaoHanh = value;
            }
        }

        public int ThoiGianSuDung
        {
            get
            {
                return this.mThoiGianSuDung;
            }
            set
            {
                this.mThoiGianSuDung = value;
            }
        }

        public string TinhTrang
        {
            get
            {
                return this.mTinhTrang;
            }
            set
            {
                this.mTinhTrang = value;
            }
        }

        public double TriGiaKhauHao
        {
            get
            {
                return this.mTriGiaKhauHao;
            }
            set
            {
                this.mTriGiaKhauHao = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }
    }
}

